package com.qf.git04.demo01;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/coo")
public class CopyImage extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //防止乱码
        resp.setContentType("text/html;charset=utf-8");
        //创建cookie
        Cookie cookie = new Cookie("gitcookie", "123");
        //设置存活时间
        cookie.setMaxAge(60*60*3); //设置存活时间3小时
        cookie.setPath("/"); //代表cookie是当前应用网站最上级的cookie
        //响应给浏览器
        resp.addCookie(cookie);
        resp.getWriter().println("cookie创建完成！");
    }
}
